// src/validation/rules.ts
import type { FormRules } from "element-plus";
import { type BusData, type FlightData, type HotelData, type CustomerData } from "../types/DataTypes.ts";

// 巴士表单验证规则
export const busRules: FormRules<BusData> = {
    location: [
        { required: true, message: '地点为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '长度在2到20个字符', trigger: 'blur' }
    ],
};

// 航班表单验证规则
export const flightRules: FormRules<FlightData> = {
    flightNum: [
        { required: true, message: '航班号为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '航班号长度在2到20个字符', trigger: 'blur' }
    ],
    fromCity: [
        { required: true, message: '出发城市为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '长度在2到20个字符', trigger: 'blur' }
    ],
    arivCity: [
        { required: true, message: '到达城市为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '长度在2到20个字符', trigger: 'blur' }
    ],
    price: [
        { required: true, message: '价格为必填项', trigger: 'blur' },
        { type: 'number', min: 0, message: '价格不能为负数', trigger: 'blur' }
    ],
    totalSeat: [
        { required: true, message: '座位总数为必填项', trigger: 'blur' },
        { type: 'number', min: 1, message: '座位总数至少为1', trigger: 'blur' }
    ],
    availSeat: [
        { required: true, message: '可用座位为必填项', trigger: 'blur' },
        { type: 'number', min: 0, message: '可用座位至少为0', trigger: 'blur' }
    ]
};

// 酒店表单验证规则
export const hotelRules: FormRules<HotelData> = {
    location: [
        { required: true, message: '位置为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '长度在2到20个字符', trigger: 'blur' }
    ],
    price: [
        { required: true, message: '价格为必填项', trigger: 'blur' },
        { type: 'number', min: 0, message: '价格不能为负数', trigger: 'blur' }
    ],
    totalRoom: [
        { required: true, message: '房间总数为必填项', trigger: 'blur' },
        { type: 'number', min: 1, message: '房间总数至少为1', trigger: 'blur' }
    ],
    availRoom: [
        { required: true, message: '可用房间为必填项', trigger: 'blur' },
        { type: 'number', min: 0, message: '可用房间至少为0', trigger: 'blur' }
    ]
};

// 客户表单验证规则
export const customerRules: FormRules<CustomerData> = {
    customerId: [
        { required: true, message: '客户ID为必填项', trigger: 'blur' },
        { min: 1, max: 20, message: '客户ID长度在1到20个字符', trigger: 'blur' }
    ],
    customerName: [
        { required: true, message: '客户姓名为必填项', trigger: 'blur' },
        { min: 2, max: 20, message: '客户姓名长度在2到20个字符', trigger: 'blur' }
    ],
};

// 导出所有规则
export default {
    busRules,
    flightRules,
    hotelRules,
    customerRules
};